package org.afun.oldhand.user.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.order.adapter.OrderItemAdapter;
import org.afun.oldhand.user.javabean.BasicInformation;
import org.w3c.dom.Text;

import java.util.List;

public class UserBasicInformationAdapter extends RecyclerView.Adapter<UserBasicInformationAdapter.BasicInformtionViewHolder> {

    private List<BasicInformation> data;
    private Context context;
    private OnBasicinformtionItemClickListener onBasicinformtionItemClickListener;

    public UserBasicInformationAdapter(List<BasicInformation> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public UserBasicInformationAdapter.BasicInformtionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.user_basic_listitem, parent,false);
        return new BasicInformtionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UserBasicInformationAdapter.BasicInformtionViewHolder holder, int position) {
        holder.basicImage.setImageResource(R.drawable.defaulthead);
        holder.name.setText(data.get(position).getName());
        holder.gexingqianming.setText((data.get(position).getGexingqianming()));
        holder.id.setText(data.get(position).getID());
        holder.cellphone.setText(data.get(position).getCellphone());
        holder.address.setText(data.get(position).getAddress());

    }

    @Override
    public int getItemCount() {
        return data == null ? 0:data.size();
    }



    public class BasicInformtionViewHolder extends RecyclerView.ViewHolder{
            ImageView basicImage;
            TextView name;
            TextView gexingqianming;
            TextView id;
            TextView cellphone;
            TextView address;

        public BasicInformtionViewHolder(@NonNull View itemView) {
            super(itemView);
            basicImage = itemView.findViewById(R.id.basicimfor_pic);
            name = itemView.findViewById(R.id.basicinfor_name);
            gexingqianming = itemView.findViewById(R.id.basicinfor_gexingqianming);
            id = itemView.findViewById(R.id.basicinfor_id);
            cellphone = itemView.findViewById(R.id.basicinfor_cellphone);
            address = itemView.findViewById(R.id.basicinfor_address);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onBasicinformtionItemClickListener != null){
                        onBasicinformtionItemClickListener.onItemRecyclerItemClick(getAdapterPosition());
                    }
                }
            });
        }
    }

        public void setBasicInformtionItemClickListener(OnBasicinformtionItemClickListener listener){
            onBasicinformtionItemClickListener = listener;
        }

        public interface OnBasicinformtionItemClickListener{
            void onItemRecyclerItemClick(int position);
        }
}
